<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/default.html}">
<head>
    <title>字段类型</title>
</head>
<body>
<section layout:fragment="wrapper">
    <form class="layui-form" th:object="${entity}" action="">
        <div class="mainBox">
            <div class="main-container">
                <input type="hidden" name="id" th:value="*{id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">数据库</label>
                    <div class="layui-input-block">
                        <select name="dbType" lay-verify="required" class="layui-select" lay-search>
                            <option value="mysql" th:selected="*{dbType == 'mysql'}">mysql</option>
                            <option value="oracle" th:selected="*{dbType == 'oracle'}">oracle</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">字段类型</label>
                    <div class="layui-input-block">
                        <input type="text" name="columnType" lay-verify="required" autocomplete="off" maxlength="50"
                               placeholder="请输入字段类型" class="layui-input" th:value="*{columnType}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">属性类型</label>
                    <div class="layui-input-block">
                        <input type="text" name="attrType" lay-verify="required" autocomplete="off" maxlength="50"
                               placeholder="请输入属性类型" class="layui-input" th:value="*{attrType}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">类型名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="attrTypeName" lay-verify="" autocomplete="off" maxlength="50"
                               placeholder="请输入类型名称" class="layui-input" th:value="*{attrTypeName}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">导包</label>
                    <div class="layui-input-block">
                        <select name="importFlag" lay-verify="required" class="layui-select" lay-search>
                            <option value="2" th:selected="*{dbType == '2'}">否</option>
                            <option value="1" th:selected="*{dbType == '1'}">是</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit
                        lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
    <script th:inline="javascript">
        layui.use(['form', 'jquery', 'button'], function () {
            let form = layui.form;
            let button = layui.button;
            let $ = layui.jquery;

            form.on('submit(form-save)', function (data) {
                // 防止重复提交
                button.load({
                    elem: '[lay-submit]',
                    time: 2000,
                    done: function() {
                    }
                })

                $.ajax({
                    url: '[(@{/genFieldType/save})]',
                    data: data.field,
                    dataType: 'json',
                    contentType: 'application/x-www-form-urlencoded',
                    type: 'post',
                    success: function (result) {
                        if (result.code === '20000') {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                                parent.layui.table.reload("tb-table");
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
                return false;
            });
        })
    </script>
</section>
</body>
</html>
